package main

import (
	context2 "context"
	"fmt"
	helloworld "ginlearn/proto"
	"github.com/gin-gonic/gin"
	client "github.com/micro/micro/v3/service/client"
)

func CallRemote(context *gin.Context) {
	// 初始化客户端
	microClient := helloworld.NewHelloworldService("helloworld", client.DefaultClient)
	// 调用远程服务
	resp, err := microClient.Call(context2.TODO(), &helloworld.Request{
		Name: "CC_test",
	})

	if err != nil {
		fmt.Println("Call err: ", err)
		return
	}

	//为了方便查看，将打印结果返回给浏览器
	context.Writer.WriteString(resp.Msg)

}

func main() {
	// 1. 初始化路由 ---- 初始化web引擎
	router := gin.Default()

	// 2. 路由匹配
	router.GET("/", func(context *gin.Context) {
		context.Writer.WriteString("CC: hello world")
	})

	//router.GET("/", CallRemote)
	fmt.Println("set")
	// 3. 启动运行
	router.Run(":8080")
}
